#include "stdafx.h"
#include "SaveTo.h"



TiXmlElement *RekSave(TiXmlElement *tata,Node *korzen,TiXmlElement *el){
		el=new TiXmlElement("child");
		el->SetAttribute("etykieta",korzen->getNodeName().c_str());
		el->SetAttribute("widoczny",korzen->getVisible());
		el->SetAttribute("szerokosc",korzen->getWidth());
		el->SetAttribute("wysokosc",korzen->getHeight());
		el->SetAttribute("X",korzen->getX());
		el->SetAttribute("Y",korzen->getY());
		el->SetAttribute("kolor",korzen->getColour());
		el->SetAttribute("link",korzen->link);
		el->SetAttribute("strona",korzen->strona);
		if(korzen->last!=NULL&&korzen->link==0)
			el->LinkEndChild(RekSave(el,korzen->last,NULL));
		if(korzen->previous!=NULL&&korzen->link==0)
			tata->LinkEndChild(RekSave(tata,korzen->previous,NULL));
	return el;
};

void SaveTo(char *sciezka,Node* zero,TiXmlElement *element){ //zero korzen drzewa ("Map1")
	TiXmlDocument doc;
	element=new TiXmlElement("root");
	element->SetAttribute("etykieta",zero->getNodeName().c_str());
	element->SetAttribute("widoczny",zero->getVisible());
	element->SetAttribute("szerokosc",zero->getWidth());
	element->SetAttribute("wysokosc",zero->getHeight());
	element->SetAttribute("X",zero->getX());
	element->SetAttribute("Y",zero->getY());
	element->SetAttribute("kolor",zero->getColour());
	element->SetAttribute("link",zero->link);

	if(zero->last!=NULL&&zero->link==0)
		element->LinkEndChild(RekSave(element,zero->last,NULL));
	
	
	
	
	
	doc.LinkEndChild(element);
	doc.SaveFile(sciezka);
};
